#! /usr/bin/python
# encoding=utf-8
# Created by Fenglu Niu on 2025/5/27 14:41
from typing import List

from sqlmodel import Session, select

import common
from api.entity import CaseFlow


class CaseFlowService(object):
    @staticmethod
    def create_flow(case_flows: List[CaseFlow], session: Session, autocommit: bool = True):
        try:
            session.add_all(case_flows)
            if autocommit:
                session.commit()
        except Exception as e:
            common.get_logger().error('创建案件流程报错：{}', e)
            session.rollback()

    @staticmethod
    def list_flow(case_id, session: Session):
        return session.exec(select(CaseFlow).where(CaseFlow.case_id == case_id).order_by(CaseFlow.handle_time)).all()